package com.coder.chen.indicator;

import java.util.Random;

import com.coder.chen.indicator.adapter.FragmentAdapter;

import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class BaseActivity extends FragmentActivity {

	private static final Random RANDOM = new Random();
	FragmentAdapter mAdapter;
	ViewPager mPager;

	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;// 返回true，Menu才会显示；否则，不显示
	};

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case 1:
			final int page = RANDOM.nextInt(mAdapter.getCount());
			Toast.makeText(this, "Change to page " + page, Toast.LENGTH_LONG)
					.show();
			mPager.setCurrentItem(page);
			return true;
		case 2:
			if (mAdapter.getCount() < 10) {
				mAdapter.setCount(mAdapter.getCount() + 1);
			}
			return true;
		case 3:
			if (mAdapter.getCount() > 1) {
				mAdapter.setCount(mAdapter.getCount() - 1);
			}
			return true;

		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}
}
